package com.leozhang.app;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import java.util.Random;

public class Demo implements Runnable {
    public static Long generateID() {
        long timestamp = System.currentTimeMillis();
        String timestampStr = String.valueOf(timestamp);
        Random random = new Random();
        int randomNum = random.nextInt(900) + 100;
        return Long.valueOf(timestampStr + randomNum);
    }

    @Override
    public void run() {
        Long id = generateID();
        long timeNow = System.currentTimeMillis();
        System.out.println("Thread: " + Thread.currentThread().getName() + ", time now: " + timeNow + ", ID: " + id);
    }

    public void test() {
        int threadNum = 20;
        ExecutorService executor = Executors.newFixedThreadPool(threadNum);
        for (int i = 0; i < threadNum; i++) {
            executor.submit(new Demo());
        }
        executor.shutdown();
    }

}
